/*
 * Amaze - QT downloader for the Amazon MP3 store
 * Copyright (c) 2010-2011 Robert Keevil
 *
 * This program is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <QFileDialog>
#include "settings.h"
#include "ui_settings.h"

Settings::Settings(Amaze *parent) :
    QDialog(parent),
    ui(new Ui::Settings)
{
    amaze = parent;
    ui->setupUi(this);
    setWindowTitle(tr("%1 Settings").arg(AMAZE_NAME));
    ui->label_format_details->setText(
            tr("See Format Help for information on the tag format"\
               "\n\nN.B. The file extension will be automatically appended."));

    ui->edit_folder->setText(amaze->config->output_folder);
    ui->edit_format->setText(amaze->config->output_format);

    connect(ui->button_folder, SIGNAL(clicked()), this, SLOT(browse()));
}

Settings::~Settings()
{
    delete ui;
}

void Settings::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type())
    {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void Settings::browse()
{
    QString dir = QFileDialog::getExistingDirectory(this, tr("Save Downloads To"),
                                                    ui->edit_folder->text(),
                                                    QFileDialog::ShowDirsOnly);
    if (!dir.isEmpty())
        ui->edit_folder->setText(dir);
}

void Settings::accept()
{
    amaze->config->output_folder = ui->edit_folder->text();
    amaze->config->output_format = ui->edit_format->text();

    emit close();
}
